package cn.zyl.quartz.controller;

import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ParseServlet")
public class ParseServlet extends HttpServlet{

    private String jobName;
    private String jobGroup;

    private static AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    private static Scheduler scheduler = (Scheduler) context.getBean("scheduler");

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            getScheduler().pauseJob(JobKey.jobKey("Job1", "jobGroup"));

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            getScheduler().pauseJob(JobKey.jobKey("Job1", "jobGroup"));

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    public static Scheduler getScheduler() {
        return scheduler;
    }

}
